<template>
  <div class="all-products">
    <!-- 头部 -->
    <header class="header">
      <div class="header-content">
        <div class="header-left">
          <span class="back-arrow" @click="goBack">‹</span>
          <span class="title">网上药房</span>
        </div>
        <div class="header-right">
          <span class="home-icon">🏠</span>
          <span class="cart-icon">🛒</span>
        </div>
      </div>
    </header>

    <!-- 全部产品标题和筛选 -->
    <div class="section-header">
      <div class="header-left">
        <h2 class="section-title">全部产品</h2>
      </div>
      <div class="header-right">
        <div class="filter-icon" @click="toggleFilter">
          <div class="filter-lines">
            <div class="line"></div>
            <div class="line"></div>
          </div>
          <div class="filter-dots">
            <div class="dot"></div>
            <div class="dot"></div>
          </div>
        </div>
      </div>
    </div>

    <!-- 产品网格 -->
    <div class="products-grid">
      <div class="product-card" v-for="product in products" :key="product.id" @click="goToProductDetail(product.id)">
        <div class="product-image-container">
          <img :src="product.image" :alt="product.name" class="product-image" />
          <div v-if="product.badge" class="product-badge" :class="product.badgeClass">
            {{ product.badge }}
          </div>
        </div>
        <div class="product-info">
          <div class="product-rating">
            <span class="star">⭐</span>
            <span class="rating-text">{{ product.rating }} ({{ product.reviews }})</span>
          </div>
          <h4 class="product-name">{{ product.name }}</h4>
          <p class="product-quantity">{{ product.quantity }}</p>
          <p class="product-price">¥{{ product.price }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

const goBack = () => {
  router.back()
}

const toggleFilter = () => {
  // 筛选功能
  console.log('打开筛选')
}

const goToProductDetail = (productId: number) => {
  router.push(`/product/${productId}`)
}

// 产品数据 - 使用imgs文件夹中的图片，按照图片描述排列
const products = ref([
  { 
    id: 1, 
    name: '多维元素片', 
    quantity: '100片', 
    price: '69.80',
    image: new URL('./imgs/v2_sypcz0.svg', import.meta.url).href,
    badge: null,
    badgeClass: null,
    rating: '4.8',
    reviews: '256'
  },
  { 
    id: 2, 
    name: '朗迪碳酸钙', 
    quantity: '100片', 
    price: '69.80',
    image: new URL('./imgs/v2_sypcwt.svg', import.meta.url).href,
    badge: '新品',
    badgeClass: 'new-badge',
    rating: '4.8',
    reviews: '256'
  },
  { 
    id: 3, 
    name: '多维元素片', 
    quantity: '100片', 
    price: '69.80',
    image: new URL('./imgs/v2_sypcxi.svg', import.meta.url).href,
    badge: null,
    badgeClass: null,
    rating: '4.8',
    reviews: '256'
  },
  { 
    id: 4, 
    name: '朗迪碳酸钙', 
    quantity: '100片', 
    price: '69.80',
    image: new URL('./imgs/v2_sypczp.svg', import.meta.url).href,
    badge: '-30%',
    badgeClass: 'discount-badge',
    rating: '4.8',
    reviews: '256'
  },
  { 
    id: 5, 
    name: '多维元素片', 
    quantity: '100片', 
    price: '69.80',
    image: new URL('./imgs/v2_sypcz0.svg', import.meta.url).href,
    badge: null,
    badgeClass: null,
    rating: '4.8',
    reviews: '256'
  },
  { 
    id: 6, 
    name: '朗迪碳酸钙', 
    quantity: '100片', 
    price: '69.80',
    image: new URL('./imgs/v2_sypcy2.svg', import.meta.url).href,
    badge: '新品',
    badgeClass: 'new-badge',
    rating: '4.8',
    reviews: '256'
  }
])
</script>

<style scoped>
.all-products {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: #f5f5f5;
  min-height: 100vh;
}

/* 头部样式 */
.header {
  background: linear-gradient(135deg, #4A90E2 0%, #357ABD 100%);
  padding: 16px 20px 12px;
  color: white;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 2px 12px rgba(74, 144, 226, 0.3);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.back-arrow {
  font-size: 28px;
  font-weight: 300;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background-color 0.2s ease;
}

.back-arrow:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.header-right {
  display: flex;
  gap: 20px;
}

.home-icon, .cart-icon {
  font-size: 22px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
  position: relative;
}

.home-icon:hover, .cart-icon:hover {
  background-color: rgba(255, 255, 255, 0.1);
  transform: scale(1.05);
}

.cart-icon::after {
  content: '';
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  background: #FF6B6B;
  border-radius: 50%;
  border: 2px solid white;
}

/* 全部产品标题和筛选 */
.section-header {
  background: white;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #e0e0e0;
}

.header-left {
  display: flex;
  align-items: center;
}

.section-title {
  font-size: 18px;
  font-weight: bold;
  color: #333;
  margin: 0;
}

.header-right {
  display: flex;
  align-items: center;
}

.filter-icon {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 8px;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.filter-icon:hover {
  background-color: #f0f0f0;
}

.filter-lines {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.line {
  width: 12px;
  height: 2px;
  background: #666;
  border-radius: 1px;
}

.filter-dots {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dot {
  width: 2px;
  height: 2px;
  background: #666;
  border-radius: 50%;
}

/* 产品网格 */
.products-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  padding: 20px;
}

.product-card {
  background: white;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.product-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.product-image-container {
  position: relative;
  margin-bottom: 12px;
  /* background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%); */
  border-radius: 12px;
  padding: 12px;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-image {
  width: 100%;
  height: 110px;
  border-radius: 8px;
  object-fit: contain;
  background: transparent;
  padding: 0;
}

.product-badge {
  position: absolute;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: bold;
  color: white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  z-index: 2;
}

.new-badge {
  background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
  top: 8px;
  left: 8px;
}

.discount-badge {
  background: linear-gradient(135deg, #4A90E2 0%, #357ABD 100%);
  top: 8px;
  left: 8px;
}

.product-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.product-rating {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 2px;
}

.star {
  font-size: 14px;
  color: #FFD700;
}

.rating-text {
  font-size: 13px;
  color: #888;
  font-weight: 500;
}

.product-name {
  font-size: 15px;
  font-weight: 600;
  color: #333;
  margin: 0;
  line-height: 1.3;
  margin-bottom: 2px;
}

.product-quantity {
  font-size: 13px;
  color: #666;
  margin: 0;
  margin-bottom: 4px;
}

.product-price {
  font-size: 18px;
  font-weight: bold;
  color: #F44336;
  margin: 0;
  margin-top: auto;
}

/* 响应式设计 */
@media (max-width: 480px) {
  .header {
    padding: 12px 16px 8px;
  }
  
  .back-arrow {
    font-size: 24px;
    width: 28px;
    height: 28px;
  }
  
  .title {
    font-size: 18px;
  }
  
  .home-icon, .cart-icon {
    font-size: 20px;
    width: 32px;
    height: 32px;
  }
  
  .products-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 16px;
  }
  
  .product-card {
    padding: 12px;
    border-radius: 12px;
  }
  
  .product-image-container {
    min-height: 100px;
    padding: 8px;
  }
  
  .product-image {
    height: 90px;
    object-fit: contain;
  }
  
  .product-name {
    font-size: 14px;
  }
  
  .product-quantity {
    font-size: 12px;
  }
  
  .product-price {
    font-size: 16px;
  }
  
  .product-badge {
    padding: 3px 6px;
    font-size: 10px;
    top: 6px;
    left: 6px;
  }
}
</style> 